//
//  BDGuideViewController.m
//  BadBoy
//
//  Created by wen on 2017/6/3.
//  Copyright © 2017年 com.8xiong. All rights reserved.
//

#import "BDGuideViewController.h"

@interface BDGuideViewController ()

@end

@implementation BDGuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UIScrollView *scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, kBDScreenWidth, kBDScreenHeight)];
    scrollView.contentSize = CGSizeMake(kBDScreenWidth * 2, 0);
    scrollView.pagingEnabled = YES;
    scrollView.bounces = NO;
    scrollView.showsVerticalScrollIndicator = NO;
    scrollView.showsHorizontalScrollIndicator = NO;
    for (int i = 0; i < 2; i++) {
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(kBDScreenWidth * i, 0, kBDScreenWidth, kBDScreenHeight)];
        NSString *imageName = [NSString stringWithFormat:@"yindao_%d.jpg", i + 1];
        UIImage *curImage = [UIImage imageNamed:imageName];
        imageView.image = curImage;
        [scrollView addSubview:imageView];
    }
    scrollView.backgroundColor = [UIColor redColor];
    
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.size = CGSizeMake(155, 40);
    button.bottom = kBDScreenHeight - 100;
    button.centerX = kBDScreenWidth * 1.5;
    button.layer.masksToBounds = YES;
    button.layer.cornerRadius = 20;
    button.layer.borderColor = [UIColor colorWithHexString:@"#666666"].CGColor;
    button.layer.borderWidth = 1.0;
    [button setTitle:ASLocalizedString(@"开启夜城之旅")forState:UIControlStateNormal];
    [button setTitleColor:[UIColor colorWithHexString:@"#666666"] forState:UIControlStateNormal];
    button.titleLabel.font = [UIFont systemFontOfSize:14];
    button.backgroundColor = [UIColor whiteColor];

    [scrollView addSubview:button];
    [button addTarget:self action:@selector(doneButtonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:scrollView];
}

- (void)doneButtonAction{
    if (self.finishedGuideBlock) {
        //获取当前版本判断是否需要显示引导页
        NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
        // app版本
        NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
        [[NSUserDefaults standardUserDefaults] setObject:@YES forKey:app_Version];
        self.finishedGuideBlock();
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        [window addSubview:self.view];
        [UIView animateWithDuration:0.3 animations:^{
            self.view.right = 0;
        } completion:^(BOOL finished) {
            [self.view removeFromSuperview];
        }];
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
